package model.xmlconvert;

import java.util.*;
import nu.xom.*;
import model.event.*;

public abstract class ModelFlowChartComponent {

	protected LinkedList<ModelLinkFlowChartComponent> connectedComponentsList;
	private final String label;
	private LinkedList<ModelComponentChangeListiner> listinerList;
	protected String operation;

	public abstract Element getXML();
	public abstract boolean addComponentConnection(ModelFlowChartComponent m);
	public abstract boolean setOperation(String operation);
	
	public ModelFlowChartComponent(String label) {
		this.label = label;
		listinerList = new LinkedList<ModelComponentChangeListiner>();
		connectedComponentsList = new LinkedList<ModelLinkFlowChartComponent>();
	}

	public void fireModelChangeEvent(ModelChangeEvent e) {
		for (ModelComponentChangeListiner m : listinerList) {
			m.changeEvent(e);
		}
	}

	public void fireModelChangeEvent() {
		this.fireModelChangeEvent(new ModelChangeEvent(this));
	}

	public void addModelChangeListiner(ModelComponentChangeListiner m) {
		this.listinerList.add(m);
	}

	public Iterator<ModelLinkFlowChartComponent> getComponentConnections() {
		return connectedComponentsList.iterator();
	}

	void deleteComponent() {
		for (ModelLinkFlowChartComponent l : connectedComponentsList) {
			l.deleteComponent();
		}

		this.fireModelChangeEvent();
	}

	void deleteConnection(ModelLinkFlowChartComponent c) {
		connectedComponentsList.remove(c);
		this.fireModelChangeEvent();
	}

	public String getOperation() {
		return operation;
	}
	
	public String getLabel() {
		return label;
	}

	
}